package com.lang.progress;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.atomic.AtomicLong;

@Slf4j
public class LogWhenCount implements DWhenCount {

    private final String operation;

    public LogWhenCount(String operation) {
        this.operation = operation;
    }

    /**
     * 下载计数
     *
     * @param name     名称
     * @param count    本次计数
     * @param hasDone  已完成数
     * @param fileSize 文件长度
     * @param done     是否已完成
     */
    @Override
    public void whenCount(String name, Long count, AtomicLong hasDone, Long fileSize, Boolean done) {
        if (done) {
            log.info("{}完成 文件={}", this.operation, name);
            return;
        }

        log.info("文件={} 已{}={}", name, this.operation, percentPretty(hasDone.get(), fileSize));
    }
}
